package com.liuwei.classy.controller;

import com.liuwei.classy.model.User;
import com.liuwei.classy.service.bizinter.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by qingshengzheng on 17/11/18.
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/")
    @ResponseBody
    public String hello() {
        return "Hello World12";
    }

    @RequestMapping("/name")
    @ResponseBody
    public String hello1() {
        return "Hello name";
    }

    /**
     * 第三方登陆
     *
     * @return
     */
    @RequestMapping(value = "/socialogin", method = RequestMethod.POST)
    @ResponseBody
    public String socialLogin(@RequestBody User user) {
        User temp = userService.userLogin(user.getOpenid(), user.getType());
        return responseJson(temp);
    }


    /**
     * 获取用户基本信息
     *
     * @return
     */
        @RequestMapping(value = "/userinfo", method = RequestMethod.GET)
    @ResponseBody
    public String getUseInfo() {
        Long uid = getHeader().getUid();
        User user = userService.userDetailByUid(uid);
        return responseJson(user);
    }


}
